package com.mangatta.cloud;

import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.services.cloudwatch.AmazonCloudWatchClient;
import com.amazonaws.services.ec2.AmazonEC2Client;

public class AmazonCloudWatchFactory {
    private final AWSCredentials awsCredentials;
    private AmazonEC2Client amazonEC2Client;
    private AmazonCloudWatchClient amazonCloudWatchClient;

    public AmazonCloudWatchFactory(AWSCredentials awsCredentials) {
        this.awsCredentials = awsCredentials;
    }

    public AmazonEC2Client getAmazonEC2Client() {
        if (amazonEC2Client == null) {
            synchronized (this) {
                if (amazonEC2Client == null) {
                    amazonEC2Client = new AmazonEC2Client(awsCredentials);
                    amazonEC2Client.setEndpoint(AwsDetail.AMAZON_EC2.getEndPoint());
                }
            }
        }
        return amazonEC2Client;
    }

    public AmazonCloudWatchClient getAmazonCloudWatchClient() {
        if (amazonCloudWatchClient == null) {
            synchronized (this) {
                if (amazonCloudWatchClient == null) {
                    amazonCloudWatchClient = new AmazonCloudWatchClient(awsCredentials);
                }
            }
        }
        return amazonCloudWatchClient;
    }
}
